
import { defineStore } from 'pinia'
import router from '@/router'
export const useViewTagsStore = defineStore("viewTags", {
	state: () => {
		return {
			viewTags: [],
		}
	},
	getters: {
		getViewTags() {
			if (this.viewTags.length > 0) {
				return this.viewTags
			}

			else {
				return null
			}

		}
	},
	actions: {
		pushViewTags(route: any) {
			if (this.viewTags.every(item => item.path !== route.path)) {
				this.viewTags.push(route);
			}
		},
		// Set Tabs
		async setTabs(viewTags: any) {
			this.viewTags = viewTags;
		},
		/**
		 * 未使用
		 */
		removeViewTags(route: any) {
			this.viewTags.forEach((item, index) => {
				if ((item as any).fullPath === route.fullPath) {
					this.viewTags.splice(index, 1);
				}
			});
		},
		updateViewTags(route) {
			if (this.viewTags.length > 0) {
				this.viewTags.forEach((item) => {
					if (item.fullPath == route.fullPath) {
						item = route;
					}
				});
			}
		},
		/**
		 * 未使用
		 */
		updateViewTagsTitle(title: any = "") {
			const nowFullPath = location.hash.substring(1);
			this.viewTags.forEach((item: any) => {
				if (item.fullPath == nowFullPath) {
					item.meta.title = title;
				}
			});
		},
		// Close MultipleTab
		async closeMultipleTab(tabsMenuValue?: string) {
			this.viewTags = this.viewTags.filter(item => {
				return item.fullPath === tabsMenuValue;
			});
		},
		/**
		 * 未使用
		 */
		clearViewTags() {
			this.viewTags = [];
		},
	}
})